package com.itheima.controller;


import com.itheima.anno.Log;
import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import org.apache.coyote.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result page (StuQueryParam stuQueryParam){

        PageResult pageResult =  studentService.page(stuQueryParam);

        return Result.success(pageResult);
    }
    @Log
    @DeleteMapping("{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        studentService.delete(ids);
        return Result.success();

    }
    @Log
    @PostMapping
    public Result add(@RequestBody Student student) throws BusinessException {
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result getInfo(@PathVariable Integer id){
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id, @PathVariable Integer score){
        studentService.violationHandle(id, score);
        return Result.success();
    }


}
